package com.component.common;

import android.telecom.Call;
import android.telecom.CallAudioState;

import com.easemob.helpdesk.utils.CommonUtils;
import com.facebook.react.ReactApplication;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class UtilsModule  extends ReactContextBaseJavaModule {

    private  ReactApplicationContext reactContext;
    private  ReactApplication reactApplication;

    @Override
    public String getName() {
        /**
         * return the string name of the NativeModule which represents this class in JavaScript
         * In JS access this module through React.NativeModules.OpenSettings
         */
        return "CommonUtils";
    }




    @ReactMethod
    public void getVersion(Callback cb) {
        String version = CommonUtils.getAppVersionCodeFromApp(reactContext);
        cb.invoke(version);
    }

    @ReactMethod
    public void getVersionName(Callback cb){
        String versionName = CommonUtils.getAppVersionNameFromApp(reactContext);
        cb.invoke(versionName);
    }

    @ReactMethod
    public void getVersionAndCode(Callback cb){
        String versionCode = CommonUtils.getAppVersionCodeFromApp(reactContext);
        String versionName = CommonUtils.getAppVersionNameFromApp(reactContext);
        cb.invoke(versionCode,versionName);
    }

    /* constructor */
    public UtilsModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.setReactContext(reactContext);
    }


    public void setReactContext(ReactApplicationContext reactContext){
        this.reactContext = reactContext;
    }

    public ReactApplicationContext getReactContext (){
        return reactContext;
    }
}
